﻿using DatabaseAccess;
using Liguo.AppCode;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Liguo.Store
{
    public partial class My : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] == null)
            {
                Response.Redirect("Port.aspx");
            }
            else
            {
                User user = (User)Session["User"];
                TbName.Text = user.UserName;
                TbMail.Text = user.MailBox;
            }
        }

        protected void BtnChgPwd_Click(object sender, EventArgs e)
        {
            if (Session["User"] == null)
            {
                Response.Redirect("Port.aspx");
            }
            else
            {
                User user = (User)Session["User"];
                String PwdMD5Old = Utilities.GetMD5(TbPwdOld.Text + user.Salt);
                if (PwdMD5Old.Equals(user.Password))
                {
                    if (TbPwdNew.Text.Length > 0)
                    {
                        String PwdMd5New = Utilities.GetMD5(TbPwdNew.Text + user.Salt);
                        new SqlIt().SpecialUpdate("UserInfo", "Password='" + PwdMd5New + "'", "ID='" + user.UserID + "'");
                        user.Password = PwdMd5New;
                        Response.Write("<script>alert(\"密码修改成功！\");</script>");
                        TbPwdOld.Text = "";
                        TbPwdNew.Text = "";
                    }
                    else
                    {
                        Response.Write("<script>alert(\"新密码不能为空！\");</script>");
                        TbPwdOld.Text = "";
                        TbPwdNew.Text = "";
                    }
                }
                else
                {
                    Response.Write("<script>alert(\"原密码不匹配！\");</script>");
                    TbPwdOld.Text = "";
                    TbPwdNew.Text = "";
                }
            }
        }
    }
}